package com.sg.service.biz.bff.nb;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.sg.common.annotations.BanAuto;
import com.sg.common.redis.SpaceInfoForRedis;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.GetSpaceInfoFromRedisReqDto;
import com.sg.dto.biz.bff.res.GetSpaceInfoFromRedisRespDto;
import com.sg.dto.integration.framework.OrgDto;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.stream.Collectors;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
@BanAuto
public class NbCommon {
    /**
     * code:getSpaceInfoFromRedis
     * name:Redis获取空间信息
     * desc:undefined
     **/
    @Resource
    private RedisUtil redisClient;

    @BanAuto
    public GetSpaceInfoFromRedisRespDto getSpaceInfoFromRedis(GetSpaceInfoFromRedisReqDto reqDto) {
        GetSpaceInfoFromRedisRespDto retData = new GetSpaceInfoFromRedisRespDto();
        String str = (String) redisClient.get(reqDto.getSpaceId());
        if (str == null || str.isEmpty()) {
            return null;
        }
        SpaceInfoForRedis redisData = JSONObject.parseObject(str, SpaceInfoForRedis.class);
        if (redisData == null) {
            return null;
        }
        BeanUtil.copyProperties(redisData, retData);
        if (redisData.getOrgList() == null) {
            retData.setOrgList(new ArrayList<>());
        } else {
            retData.setOrgList(redisData.getOrgList().stream().map(p -> {
                OrgDto retElm = new OrgDto();
                BeanUtil.copyProperties(p, retElm);
                return retElm;
            }).collect(Collectors.toList()));
        }
        return retData;
    }
    //手工接入方法
}
